//商品属性管理模块接口
import request from '@/utils/request'
import type { AttrResponseData, CategoryResponseData, Attr } from './type'
//引入属性管理接口地址
enum API {
  C1_URL = '/admin/product/getCategory1',
  C2_URL = '/admin/product/getCategory2',
  C3_URL = '/admin/product/getCategory3',
  //获取分类下已有属性和属性值
  ATTR_URL = '/admin/product/attrInfoList/',
  //添加或修改属性的接口
  ADDORUPDATEATTR_URL = '/admin/product/saveAttrInfo',
  //删除某一个已有属性
  DELETEATTR_URL = '/admin/product/deleteAttr/{attrId}',
}

//获取一级分类的接口方法
export const reqC1 = () => {
  request.get<any, CategoryResponseData>(API.C1_URL)
}
//获取二级分类的接口方法
export const reqC2 = (category1Id: number | string) => {
  request.get<any, CategoryResponseData>(API.C2_URL + category1Id)
}
//获取三级分类的接口方法
export const reqC3 = (category2Id: number | string) => {
  request.get<any, CategoryResponseData>(API.C3_URL + category2Id)
}
//获取已有分类属性与属性值的方法
export const reqAttr = (
  category1Id: number | string,
  category2Id: number | string,
  category3Id: number | string,
) => {
  request.get<any, AttrResponseData>(
    API.ATTR_URL + `${category1Id}/${category2Id}/${category3Id}`,
  )
}
//新增或修改属性的接口方法
export const reqAddOrUpdateAttr = (data: Attr) => {
  request.post<any, Attr>(API.ADDORUPDATEATTR_URL, data)
}
//删除某一个属性的方法
export const reqRemoveAttr = (attrId: number) =>
  request.delete<any, any>(API.DELETEATTR_URL + attrId)
